package com.wanhe.viewconf.views.child;

import android.content.Context;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wanhe.base.model.base.Dish;
import com.wanhe.base.model.disgn.Event;
import com.wanhe.base.model.disgn.ViewEvent;
import com.wanhe.base.model.disgn.ViewItem;
import com.wanhe.base.model.holder.DishHolder;
import com.wanhe.base.util.ObjectUtil;
import com.wanhe.viewconf.ViewCreator;
import com.wanhe.viewconf.views.base.text.AutoTextSizeTextView;
import com.wanhe.viewconf.views.child.MealBookChildItemView;

/**
 * File Name:MealBookTextView.java<br/>
 * Package Name:com.wanhe.viewconf.views.child.text<br/>
 * Date:2017/7/4 16:54<br/>
 * author:chendeji<br/>
 * desc: 菜单页面上的文本信息控件<br/>
 * Copyright (c) 2017/7/4, 781571323@qq.com All Rights Reserved.
 *
 */
public class MealBookTextView extends MealBookChildItemView {

	public static final String	TAG	= "MealBookTextView";
	private final TextView		textView;

	public MealBookTextView(Context context) {
		super(context);
		textView = new TextView(context);
		textView.setGravity(Gravity.RIGHT);
		textView.setTextSize(TypedValue.COMPLEX_UNIT_PT,
				ViewCreator.getInstance().getTxtFontSize());
		textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
				ViewGroup.LayoutParams.MATCH_PARENT));
		textView.setTypeface(ViewCreator.getInstance().getFontTypeface());
		addView(textView);
	}

	@Override
	public void initModelData(ViewItem item) {
		super.initModelData(item);
		if (ObjectUtil.checkObject(this.mDish)) {
			setData(item, this.mDish);
		}
	}

	@Override
	public void setViewColor(String color) {
		super.setViewColor(color);
		textView.setTextColor(getColor());
	}

	private void setData(ViewItem item, Dish dish) {
		switch (item.getType()) {
			case "price1" :
				textView.setText(String.valueOf((int) dish.getNum_price1()));
				break;
			case "txt1" :
				break;
			case "price2" :
				textView.setText(String.valueOf((int) dish.getNum_price2()));
				break;
			case "name" :
				textView.setText(dish.getVch_dishname());
				break;
		}
	}

	@Override
	public void show(Event event, ViewEvent.Coor coor) {
		super.show(event, coor);
	}

	@Override
	public void hide(Event event, ViewEvent.Coor coor) {
		super.hide(event, coor);
	}

	@Override
	public void set(Event event, ViewEvent.Coor coor) {
		// 1，将事件的数据解析出来
		if (ObjectUtil.checkObject(event)) {
			Event.ArgsBean args = event.getArgs();
			Dish dish = DishHolder.getInstance().get(args.getDishID());
			if (ObjectUtil.checkObject(dish)) {
				setData(this.mItem, dish);
				setViewStatu(VIEW_DIRTY);
				requestLayout();
				textView.invalidate();
			}
		}
	}
}
